package com._520it.crm.web.controller;

import com._520it.crm.domain.Role;
import com._520it.crm.page.PageResult;
import com._520it.crm.query.RoleQueryObject;
import com._520it.crm.service.IRoleService;
import com._520it.crm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/role")
public class RoleController {
    @Autowired
    IRoleService roleService;

    @RequestMapping("")
    public String index(){
        return "role";
    }


    @RequestMapping("list")
    @ResponseBody
    public PageResult list(RoleQueryObject qo){
        PageResult result = null;
        result  = roleService.queryPage(qo);
        return result;
    }
    @RequestMapping("/save")
    @ResponseBody
    public AjaxResult save(Role role){
      AjaxResult result = null;
      try{
          roleService.insert(role);
          result = new AjaxResult("添加成功");
      }catch(Exception e){
          result = new AjaxResult(false,"添加失败");
      }
      return result;
    }
    @RequestMapping("/update")
    @ResponseBody
    public AjaxResult update(Role role){
      AjaxResult result = null;
      try{
          roleService.updateByPrimaryKey(role);
          result = new AjaxResult("更新成功");
      }catch(Exception e){
          result = new AjaxResult(false,"更新失败");
      }
      return result;
    }
    @RequestMapping("/queryRoleList")
    @ResponseBody
    public List<Role> queryRoleList(Role role){
       List<Role> result = null;
        result = roleService.selectAll();
    return result;
    }
    @RequestMapping("/queryRoleIdByEmployeeId")
    @ResponseBody
    public List<Role> queryRoleIdByEmployeeId(Long employeeId){
       List<Role> result = null;
        result = roleService.queryRoleIdByEmployeeId(employeeId);
    return result;
    }

}
